// pages/local video/locla video.ts
Page({
  data: {
    selectedVideoPath: '',
    savedVideos: [],
    isPlayingSelected: false
  },

  chooseVideo: function () {
    wx.chooseMedia({
      count: 1,
      mediaType: ['video'],
      sourceType: ['album', 'camera'],
      success: (result) => {
        this.setData({
          selectedVideoPath: result.tempFiles[0].tempFilePath,
          isPlayingSelected: true
        });
      }
    });
  },

  playSavedVideo: function (event) {
    // 播放保存的视频的逻辑
    if (event.currentTarget.dataset.path) {
      wx.showToast({
        title: '正在播放视频',
        icon: 'uccess'
      });
      // 假设微信提供了类似 playVideo 的方法
      // wx.playVideo(event.currentTarget.dataset.path); 
    } else {
      wx.showToast({
        title: '请先选择视频',
        icon: 'none'
      });
    }
  },

  saveVideo: function () {
    let selectedVideoPath = this.data.selectedVideoPath;
    if (selectedVideoPath) {
      this.data.savedVideos.push(selectedVideoPath);
      wx.setStorageSync('savedVideos', this.data.savedVideos);
      this.setData({
        savedVideos: this.data.savedVideos
      });
    }
  },

  deleteVideo: function (event) {
    let index = event.currentTarget.dataset.index;
    this.data.savedVideos.splice(index, 1);
    wx.setStorageSync('savedVideos', this.data.savedVideos);
    this.setData({
      savedVideos: this.data.savedVideos
    });
  },

  onLoad: function () {
    let savedVideos = wx.getStorageSync('savedVideos') || [];
    this.setData({
      savedVideos: savedVideos
    });
  }
})